fix: wrap keyboard selection in the @ file picker - #769
Open
killersteps wants to merge 1 commit into
Open
Conversation
ArrowDown at the last match and ArrowUp at the first match currently clamp, so the list cannot be cycled. Wrap the active index so the highlighted row returns to the other end, matching typical picker UX.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ArrowDown on the
@file picker clamps at the last match. Once the highlight is on the bottom row, another Down does nothing, so you cannot wrap back to the first file. ArrowUp has the same clamp at the top.The list is already scrollable and already calls
scrollIntoViewon the active row. The missing piece is cycling the index.Solution
Wrap the active index in both directions:
Existing
scrollIntoView({ block: "nearest" })then brings the opposite end into the visible list.Tests
cycleListIndexunit cases for both directions, a single-item list, and an empty list.node --experimental-strip-types --test components/ChatInput.test.mjspasses.问题
@文件列表里按 ↓ 到最后一项会被夹住。高亮已经在最后一行时,再按 ↓ 没有反应,没法回到第一项。↑ 在第一项同样被夹住。列表本身可以滚动,高亮行也已经会
scrollIntoView。缺的只是下标循环。解决方案
两个方向都循环高亮下标:
现有的
scrollIntoView({ block: "nearest" })会把另一端滚进可见区域。测试
cycleListIndex覆盖双向循环、只有一项、空列表。node --experimental-strip-types --test components/ChatInput.test.mjs通过。